<template>
    <div class="container">
      <h2 class="title">商品分类管理</h2>
      <form @submit.prevent="addCategory">
        <div class="form-group">
          <label for="category-name">分类名称</label>
          <input type="text" id="category-name" v-model="newCategoryName" placeholder="输入分类名称">
        </div>
        <button type="submit" class="btn-add">添加分类</button>
      </form>
      <ul class="category-list">
        <li v-for="(category, index) in categories" :key="index">{{ category }}</li>
        <li>手机</li>
        <li>家电</li>
        <li>饮料</li> 
      </ul>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        newCategoryName: '',
        categories: []
      };
    },
    methods: {
      addCategory() {
        if (this.newCategoryName.trim()) {
          this.categories.push(this.newCategoryName);
          this.newCategoryName = '';
        }
      }
    }
  };
  </script>
  
  <style scoped>
  .container {
    max-width: 400px;
    margin: 0 auto;
    padding: 40px;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  
  .title {
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 20px;
  }
  
  .form-group {
    margin-bottom: 20px;
  }
  
  .form-group label {
    display: block;
    font-weight: bold;
    margin-bottom: 5px;
  }
  
  .form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
  }
  
  .btn-add {
    display: block;
    width: 100%;
    padding: 10px;
    background-color: #4caf50;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    font-weight: bold;
  }
  
  .category-list {
    list-style: none;
    padding: 0;
  }
  
  .category-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background-color: #f0f6fd;
    margin-bottom: 10px;
    border-radius: 4px;
  }
  
  .category-list li:last-child {
    margin-bottom: 0;
  }
  </style>